/**
 *	@file	telseq_gantetsu.c
 *	@brief	ガンテツ　会話データ抽選＆再生
 *	@author	Miyuki Iwasawa
 *	@date	09.02.06
 */

#include "common.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/buflen.h"
#include "system/pm_rtc.h"
#include "gflib/touchpanel.h"
#include "field/eventflag.h"
#include "field/evwkdef.h"
#include "fielddata/script/saveflag.h"
#include "savedata/bonguri.h"
#include "itemtool/itemsym.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_pg_tel.h"
#include "msgdata/msg_tel_p_gantetsu.h"

#include "../pm_tel.h"
#include "tel/pmtel_def.h"
#include "tel/pmtel_datman.h"
#include "tel/pmtel_dat_def.h"
#include "../pmtel_seq.h"
#include "telseq_play.h"

/**
 *	@brief	電話　ガンテツの会話抽選
 */
u16 PMTelPlayL_Gantetsu(PMTEL_DATA_MAN* man,PMTEL_TALK_WORK* wk)
{
	wk->seq_code = TEL_SEQ_SIMPLE;

	//同一マップにいるか？
	if(wk->pbk->map_id == man->zone_id)	{
		return TEL_TK_GANTETSU_NE;
	}
	//ノーマル発信
	wk->seq_code = TEL_SEQ_GANTETSU_CALL;
	return 0;
}

/**
 *	@brief	ガンテツの送信会話シーケンス
 */
int PMTelSeq_TypeGantetsuCall(PMTEL_DATA_MAN* man)
{
	PMTEL_TALK_WORK *wk = &man->twk;
	switch(wk->seq){
	case 0:
		//タグ展開処理
		PMTel_TagSpreadCommon(man);

		//挨拶出力
		if(EventWork_CheckEventFlag(man->ev_sv,FE_GANTETSU_REGULAR_CUSTOMER)){
			PMTel_MsgPrintGmm(man,man->m_person,m_gantetsu_05);
		}else{
			PMTel_MsgPrintGmm(man,man->m_person,m_gantetsu_01);
		}
		break;
	case 1:
		if(!PMTel_MsgPrintWait(man)) return FALSE;
		{
			u8 ball_num,msg;
			BONGURI_SAVE* bong = SaveData_GetBonguriSave(man->save);

			ball_num = BonguriSave_GetKeepBonguriNum(bong);

			if(ball_num == 0){	//預けてない
				msg = m_gantetsu_04;
			}else if(EventWork_CheckEventFlag(man->ev_sv,TMFLG_BONGURI_BALL)){	//預けてる
				msg = m_gantetsu_03;
			}else{
				WORDSET_RegisterItemName( man->wset, WORDSET_TEL_LOCAL_BUF,
					BonguriSave_ExchangeKeepBonguri(bong));
				WORDSET_RegisterNumber( man->wset, WORDSET_TEL_LOCAL_BUF+1,
					ball_num, 2,	NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
				msg = m_gantetsu_02;
			}
			PMTel_MsgPrintGmm(man,man->m_person,msg);
		}
		break;
	default:
		if(!PMTel_MsgPrintWait(man)) return FALSE;
		MSGMAN_Delete(man->m_person);
		return TRUE;
	}
	++wk->seq;
	return FALSE;
}
